Skip to content

Add Claude Code smart routing - #255

Open
masonc08 wants to merge 1 commit into
codex-intelligent-routingfrom
claude-smart-routing
Open

Add Claude Code smart routing#255
masonc08 wants to merge 1 commit into
codex-intelligent-routingfrom
claude-smart-routing

Conversation

@masonc08

Copy link
Copy Markdown
Collaborator

What & why

Extends smart routing to Claude Code, on top of the shared smart-routing engine introduced in the base PR #251. ucode claude --enable-smart-routing opts a workspace into AI Gateway model routing for Claude Code:

  • Root session — the workspace task_v1 router picks between claude-opus-4-8 and claude-sonnet-5; the pick is pinned via ANTHROPIC_MODEL.
  • Subagents — a PreToolUse hook (matcher Agent|Task) rewrites the spawned subagent's model via hookSpecificOutput.updatedInput; SessionStart/SubagentStart hooks drive a canary + audit trail.
  • --disable-smart-routing surgically removes only ucode's own hooks and clears artifacts.

The two Claude arms are offered to the router unconditionally, matching the frozen task_v1 cc-scenario menu (which rejects an under-offered request); if an arm isn't servable it fails open to the family default. Reads the shared smart_routing_enabled state key, so one opt-in covers both Codex and Claude Code.

Stacking

Stacked on #251 (base branch codex-intelligent-routing), which carries the shared engine + rename. This PR only adds Claude-specific files and wiring; it touches no Codex routing logic. Review #251 first — once it merges this will be rebased onto main.

How do you know it works?

  • New test_claude_routing.py: the cc-menu request shape, the missing-arm short-circuit, router-pick → workspace-id resolution, fail-open on router error, the subagent model rewrite (Agent and Task tool names), and the decision→SubagentStart audit reconciliation.
  • New Claude cases in test_agent_claude.py: enable/disable, hook installation into ucode-settings.json, the ANTHROPIC_MODEL root pin, and provider-mode suppression of routing hooks.
  • Full suite green (1062 passed); ruff + ty lint gate green. The pre-existing test_e2e_user_agent failure needs a live gateway and fails identically on the base branch.

Not yet validated with a live/liteswap Claude Code session, and routing only activates once the task_v1 router serves harness: "claude" in the target workspace.

This pull request and its description were written by Isaac.

@masonc08
masonc08 force-pushed the claude-smart-routing branch from 504ca15 to 0383b91 Compare July 31, 2026 19:35
@masonc08
masonc08 force-pushed the codex-intelligent-routing branch from a6207dd to 579a5cb Compare July 31, 2026 20:24
@masonc08
masonc08 force-pushed the claude-smart-routing branch 2 times, most recently from bce872b to f1b5ad9 Compare July 31, 2026 21:01
Extend smart routing to Claude Code on top of the shared engine. `ucode claude
--enable-smart-routing` routes the root session (via ANTHROPIC_MODEL) and
subagents (via a PreToolUse hook that rewrites the Agent tool's model) through
the workspace task_v1 router.

- smart_routing/claude_routing.py + claude_hooks.py: Claude cc-scenario arms
  (claude-opus-4-8, claude-sonnet-5, harness "claude"), both offered
  unconditionally per the frozen task_v1 menu; settings.json hook shape.
- claude agent + CLI: --enable/--disable-smart-routing, hidden
  claude-router-hook, reads the shared smart_routing_enabled state key so one
  opt-in covers codex and claude.

Co-authored-by: Isaac
@masonc08
masonc08 force-pushed the codex-intelligent-routing branch from f29d4d0 to db235b4 Compare July 31, 2026 21:18
@masonc08
masonc08 force-pushed the claude-smart-routing branch from f1b5ad9 to 659c0f1 Compare July 31, 2026 21:18
@rohita5l
rohita5l marked this pull request as ready for review July 31, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant